/**
 * Created by chenyong on 2015/4/26.
 */

'use strict';

exports.getElement = function (parentElement, elementName) {
    if (parentElement['saml:' + elementName]) {
        return parentElement['saml:' + elementName];
    } else if (parentElement['samlp:'+elementName]) {
        return parentElement['samlp:'+elementName];
    }
    return parentElement[elementName];
};

exports.getFirstElement = function (parentElement, elementName) {
    var element = null;

    if (parentElement['saml:' + elementName]) {
        element =  parentElement['saml:' + elementName];
    } else if (parentElement['samlp:'+elementName]) {
        element =  parentElement['samlp:'+elementName];
    } else {
        element = parentElement[elementName];
    }
    return Array.isArray(element) ? element[0] : element;
};